package com.yc.project.util;

import com.google.gson.Gson;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Utils {




    /**
     * 将 obj 转成 json 对象 ， 通过相应对象返回给浏览器
     * @param obj
     * @param response
     * @throws IOException
     */
    public static void toJson(Object obj, HttpServletResponse response)
            throws IOException {
        String json = new Gson().toJson(obj);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().append(json);
    }

}
